using SS.core;
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;
namespace SS
{
	internal class Func
	{
		private string[] numberArr = new string[10];
		private string[] moneyArr = new string[4];
		public string strConnectionString = "";
		public void fillCbb(ComboBox cbb)
		{
			cbb.BindingContext = new BindingContext();
			cbb.Items.Add(new SS.core.ItemCombobox("Bán buôn", "0"));
			cbb.Items.Add(new SS.core.ItemCombobox("Bán lẻ", "1"));
			cbb.Items.Add(new SS.core.ItemCombobox("Tất cả", "2"));
			cbb.SelectedIndex = 0;
		}
		public Func()
		{
			this.strConnectionString = this.GetStrConnectionString();
		}
		public void SetFocusDatagridview(DataGridView dgv, string CellValue, int CellPosition)
		{
			try
			{
				if (dgv.RowCount > 0)
				{
					for (int i = 0; i < dgv.RowCount; i++)
					{
						if (dgv.Rows[i].Cells[CellPosition].Value.ToString() == CellValue)
						{
							dgv.FirstDisplayedScrollingRowIndex = i;
							dgv.Rows[i].Selected = true;
							dgv.CurrentCell = dgv.Rows[i].Cells[0];
							dgv.BeginEdit(false);
							break;
						}
					}
				}
			}
			catch
			{
			}
		}
		public string getUnitID(string UnitName)
		{
			string result = "";
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			try
			{
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [UnitID] FROM [TabUnitProduct] WHERE [UnitName]=@a";
				sqlCommand.Parameters.AddWithValue("@a", UnitName);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				if (sqlDataReader.HasRows)
				{
					while (sqlDataReader.Read())
					{
						result = sqlDataReader["UnitID"].ToString();
					}
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
			}
			catch
			{
			}
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		public string GetStrConnectionString()
		{
			string text = ConfigurationSettings.AppSettings["ServerName"].ToString();
			string text2 = ConfigurationSettings.AppSettings["UserID"].ToString();
			string text3 = ConfigurationSettings.AppSettings["PassWord"].ToString();
			string text4 = ConfigurationSettings.AppSettings["DataBase"].ToString();
			string result = string.Concat(new string[]
			{
				"Server=",
				text,
				"; Initial Catalog=",
				text4,
				"; User Id=",
				text2,
				"; pwd=",
				text3,
				";"
			});
			this.strConnectionString = result;
			return result;
		}
		public string getConnectionStringOther()
		{
			return Program.strConnectionString;
		}
		public string DateFormating(string InputStr)
		{
			string result;
			try
			{
				DateTime.Parse("12/15/2009");
				string text;
				if (InputStr.Substring(1, 1) == "/" && InputStr.Substring(3, 1) == "/")
				{
					text = string.Concat(new string[]
					{
						"0",
						InputStr.Substring(2, 1),
						"/0",
						InputStr.Substring(0, 1),
						"/",
						InputStr.Substring(4, 4)
					});
				}
				else
				{
					if (InputStr.Substring(2, 1) == "/" && InputStr.Substring(4, 1) == "/")
					{
						text = string.Concat(new string[]
						{
							"0",
							InputStr.Substring(3, 1),
							"/",
							InputStr.Substring(0, 2),
							"/",
							InputStr.Substring(5, 4)
						});
					}
					else
					{
						if (InputStr.Substring(1, 1) == "/" && InputStr.Substring(4, 1) == "/")
						{
							text = string.Concat(new string[]
							{
								InputStr.Substring(2, 2),
								"/0",
								InputStr.Substring(0, 1),
								"/",
								InputStr.Substring(5, 4)
							});
						}
						else
						{
							if (InputStr.Substring(2, 1) == "/" && InputStr.Substring(5, 1) == "/")
							{
								text = string.Concat(new string[]
								{
									InputStr.Substring(3, 2),
									"/",
									InputStr.Substring(0, 2),
									"/",
									InputStr.Substring(6, 4)
								});
							}
							else
							{
								text = InputStr;
							}
						}
					}
				}
				result = text;
			}
			catch
			{
				result = DateTime.Parse(InputStr).ToShortDateString();
			}
			return result;
		}
		public string DateFormatingToWin(string InputStr)
		{
			string typeDate = this.getTypeDate();
			string result;
			if (typeDate != "1")
			{
				if (InputStr.Substring(1, 1) == "/" && InputStr.Substring(3, 1) == "/")
				{
					result = string.Concat(new string[]
					{
						"0",
						InputStr.Substring(2, 1),
						"/0",
						InputStr.Substring(0, 1),
						"/",
						InputStr.Substring(4, 4)
					});
				}
				else
				{
					if (InputStr.Substring(2, 1) == "/" && InputStr.Substring(4, 1) == "/")
					{
						result = string.Concat(new string[]
						{
							"0",
							InputStr.Substring(3, 1),
							"/",
							InputStr.Substring(0, 2),
							"/",
							InputStr.Substring(5, 4)
						});
					}
					else
					{
						if (InputStr.Substring(1, 1) == "/" && InputStr.Substring(4, 1) == "/")
						{
							result = string.Concat(new string[]
							{
								InputStr.Substring(2, 2),
								"/0",
								InputStr.Substring(0, 1),
								"/",
								InputStr.Substring(5, 4)
							});
						}
						else
						{
							if (InputStr.Substring(2, 1) == "/" && InputStr.Substring(5, 1) == "/")
							{
								result = string.Concat(new string[]
								{
									InputStr.Substring(3, 2),
									"/",
									InputStr.Substring(0, 2),
									"/",
									InputStr.Substring(6, 4)
								});
							}
							else
							{
								result = InputStr.Substring(0, InputStr.IndexOf(":") - 3);
							}
						}
					}
				}
			}
			else
			{
				result = InputStr.Substring(0, InputStr.IndexOf(":") - 3);
			}
			return result;
		}
		public string GetSysPer(string UserName, string PassWord)
		{
			string text = "";
			string text2 = "";
			bool flag = false;
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "SELECT [Group],[Pass] FROM [TabUser] WHERE [UserName] = '" + UserName + "'";
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			while (sqlDataReader.Read() && !flag)
			{
				if (this.CryptographyMD5(PassWord) == sqlDataReader["Pass"].ToString())
				{
					text = sqlDataReader["Group"].ToString();
					flag = true;
				}
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			if (text != "")
			{
				text = "(" + text.Replace("\"", "") + ")";
				SqlCommand sqlCommand2 = sqlConnection.CreateCommand();
				sqlCommand2.CommandText = "SELECT [GPer] FROM [TabGroup] WHERE [GID] IN" + text;
				SqlDataReader sqlDataReader2 = sqlCommand2.ExecuteReader();
				while (sqlDataReader2.Read())
				{
					text2 = text2 + sqlDataReader2["GPer"].ToString() + ",";
				}
				sqlDataReader2.Close();
				sqlDataReader2.Dispose();
				if (text2 != "")
				{
					text2 = "IN(" + text2.Remove(text2.Length - 1, 1).Replace("\"", "") + ")";
				}
			}
			sqlConnection.Close();
			sqlConnection.Dispose();
			return text2;
		}
		public int GetSysPerByUserName(string UserName)
		{
			string text = "";
			string text2 = "";
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "SELECT [Group] FROM [TabUser] WHERE [UserName] = '" + UserName + "'";
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			if (sqlDataReader.HasRows)
			{
				while (sqlDataReader.Read())
				{
					text = sqlDataReader["Group"].ToString();
				}
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			if (text != "")
			{
				text = "(" + text.Replace("\"", "") + ")";
				SqlCommand sqlCommand2 = sqlConnection.CreateCommand();
				sqlCommand2.CommandText = "SELECT [GPer] FROM [TabGroup] WHERE [GID] IN" + text;
				SqlDataReader sqlDataReader2 = sqlCommand2.ExecuteReader();
				while (sqlDataReader2.Read())
				{
					text2 = text2 + sqlDataReader2["GPer"].ToString() + ",";
				}
				sqlDataReader2.Close();
				sqlDataReader2.Dispose();
				if (text2 != "")
				{
					text2 = "IN(" + text2.Remove(text2.Length - 1, 1).Replace("\"", "") + ")";
				}
			}
			sqlConnection.Close();
			sqlConnection.Dispose();
			int result;
			if (text2.Contains("78") && text2.Contains("79"))
			{
				result = 3;
			}
			else
			{
				if (text2.Contains("78"))
				{
					result = 2;
				}
				else
				{
					if (text2.Contains("79"))
					{
						result = 1;
					}
					else
					{
						result = 0;
					}
				}
			}
			return result;
		}
		public string GetFullName(string UserName)
		{
			string result = "";
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "SELECT FullName FROM [TabUser] WHERE [UserName] = '" + UserName + "'";
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			while (sqlDataReader.Read())
			{
				result = sqlDataReader["FullName"].ToString();
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		public string GetUserGroup(string UserName)
		{
			string result = "";
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "SELECT [Group] FROM [TabUser] WHERE [UserName] = '" + UserName + "'";
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			while (sqlDataReader.Read())
			{
				result = sqlDataReader["Group"].ToString();
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		public string GetUserGroupNew(string UserName)
		{
			string text = "";
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "SELECT [Group]FROM [TabUser] WHERE [UserName] = '" + UserName + "'";
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			while (sqlDataReader.Read())
			{
				text = sqlDataReader["Group"].ToString();
				text = text.Replace("\"", "");
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			return text;
		}
		public string CryptographyMD5(string source)
		{
			MD5CryptoServiceProvider mD5CryptoServiceProvider = new MD5CryptoServiceProvider();
			byte[] bytes = Encoding.UTF8.GetBytes(source);
			byte[] array = mD5CryptoServiceProvider.ComputeHash(bytes);
			string text = "";
			byte[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				byte b = array2[i];
				text += int.Parse(b.ToString(), NumberStyles.HexNumber).ToString();
			}
			return text;
		}
		public string getValue(string tableName, string fieldName, string conditionName, string valueCompare)
		{
			string result = "";
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				string commandText = string.Concat(new string[]
				{
					"SELECT [",
					fieldName,
					"] FROM [",
					tableName,
					"] WHERE [",
					conditionName,
					"] = '",
					valueCompare,
					"'"
				});
				try
				{
					sqlCommand.CommandText = commandText;
					SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
					while (sqlDataReader.Read())
					{
						result = sqlDataReader[fieldName].ToString();
					}
					sqlDataReader.Close();
					sqlDataReader.Dispose();
				}
				catch
				{
				}
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public string getValueNumber(string objSQL, string fieldName)
		{
			string result = "0";
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			try
			{
				sqlCommand.CommandText = objSQL;
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = sqlDataReader["" + fieldName + ""].ToString();
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
			}
			catch
			{
			}
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		public void LoadComboBox(string SQL, ComboBox objCbb, string _ValueNumber, string _ValueText)
		{
			try
			{
				objCbb.BindingContext = new BindingContext();
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(SQL, sqlConnection);
				DataSet dataSet = new DataSet();
				try
				{
					sqlDataAdapter.Fill(dataSet);
					objCbb.DataSource = dataSet.Tables[0].DefaultView;
					objCbb.ValueMember = _ValueNumber;
					objCbb.DisplayMember = _ValueText;
					objCbb.SelectedIndex = 0;
				}
				catch
				{
				}
				finally
				{
					dataSet.Dispose();
					sqlConnection.Close();
					sqlConnection.Dispose();
				}
			}
			catch
			{
			}
		}
		public void loadPacketIntoComboBox(string SQL, ComboBox objCbb, string _ValueNumber, string _ValueText)
		{
			try
			{
				objCbb.BindingContext = new BindingContext();
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(SQL, sqlConnection);
				DataSet dataSet = new DataSet();
				DataTable dataTable = new DataTable();
				DataColumn column = new DataColumn(_ValueNumber, typeof(string));
				dataTable.Columns.Add(column);
				try
				{
					sqlDataAdapter.Fill(dataSet);
					for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
					{
						if (!this.checkPacketInDataDataTable(dataSet.Tables[0].Rows[i]["Packet"].ToString(), dataTable, "Packet"))
						{
							dataTable.Rows.Add(new object[]
							{
								dataSet.Tables[0].Rows[i]["Packet"].ToString()
							});
						}
					}
					objCbb.DataSource = dataTable;
					objCbb.ValueMember = _ValueNumber;
					objCbb.DisplayMember = _ValueText;
					objCbb.SelectedIndex = 0;
				}
				catch
				{
				}
				finally
				{
					dataSet.Dispose();
					sqlConnection.Close();
					sqlConnection.Dispose();
				}
			}
			catch
			{
			}
		}
		private bool checkPacketInDataDataTable(string PacketID, DataTable objTable, string FileName)
		{
			bool result = false;
			for (int i = 0; i < objTable.Rows.Count; i++)
			{
				if (objTable.Rows[i]["Packet"].ToString().Trim().ToUpper() == PacketID.Trim().ToUpper())
				{
					result = true;
				}
			}
			return result;
		}
		public void LoadComboBoxStock(string SQL, ComboBox objCbb, string _ValueNumber, string _ValueText)
		{
			try
			{
				objCbb.BindingContext = new BindingContext();
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(SQL, sqlConnection);
				DataSet dataSet = new DataSet();
				try
				{
					sqlDataAdapter.Fill(dataSet);
					dataSet.Tables[0].Rows.Add(new object[]
					{
						"0",
						"-:- TẤT CẢ CÁC KHO -:-"
					});
					objCbb.DataSource = dataSet.Tables[0].DefaultView;
					objCbb.ValueMember = _ValueNumber;
					objCbb.DisplayMember = _ValueText;
					objCbb.SelectedValue = 0;
				}
				catch
				{
				}
				finally
				{
					dataSet.Dispose();
					sqlConnection.Close();
					sqlConnection.Dispose();
				}
			}
			catch
			{
			}
		}
		public void LoadComboBoxPacket(string SQL, ComboBox objCbb, string _ValueNumber, string _ValueText)
		{
			try
			{
				objCbb.BindingContext = new BindingContext();
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(SQL, sqlConnection);
				DataSet dataSet = new DataSet();
				try
				{
					sqlDataAdapter.Fill(dataSet);
					dataSet.Tables[0].Rows.Add(new object[]
					{
						"-:- TẤT CẢ CÁC LÔ -:-",
						"0"
					});
					objCbb.DataSource = dataSet.Tables[0].DefaultView;
					objCbb.ValueMember = _ValueNumber;
					objCbb.DisplayMember = _ValueNumber;
					objCbb.SelectedText = "-:- TẤT CẢ CÁC LÔ -:-";
				}
				catch
				{
				}
				finally
				{
					dataSet.Dispose();
					sqlConnection.Close();
					sqlConnection.Dispose();
				}
			}
			catch
			{
			}
		}
		public void LoadComboBoxProduct(string SQL, ComboBox objCbb, string _ValueNumber, string _ValueText)
		{
			objCbb.BindingContext = new BindingContext();
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(SQL, sqlConnection);
			DataSet dataSet = new DataSet();
			try
			{
				sqlDataAdapter.Fill(dataSet);
				dataSet.Tables[0].Rows.Add(new object[]
				{
					"0",
					"TẤT CẢ SẢN PHẨM"
				});
				objCbb.DataSource = dataSet.Tables[0];
				objCbb.ValueMember = _ValueNumber;
				objCbb.DisplayMember = _ValueText;
				objCbb.SelectedValue = "0";
			}
			catch
			{
			}
			finally
			{
				dataSet.Dispose();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
		}
		public void LoadComboBoxGProduct(string SQL, ComboBox objCbb, string _ValueNumber, string _ValueText)
		{
			objCbb.BindingContext = new BindingContext();
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(SQL, sqlConnection);
			DataSet dataSet = new DataSet();
			try
			{
				sqlDataAdapter.Fill(dataSet);
				dataSet.Tables[0].Rows.Add(new object[]
				{
					"0",
					"TẤT CẢ NHÓM SẢN PHẨM"
				});
				objCbb.DataSource = dataSet.Tables[0];
				objCbb.ValueMember = _ValueNumber;
				objCbb.DisplayMember = _ValueText;
				objCbb.SelectedValue = "0";
			}
			catch
			{
			}
			finally
			{
				dataSet.Dispose();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
		}
		public void LoadAutoCompleteTextBox(string SQL, TextBox txt, string _ValueText)
		{
			AutoCompleteStringCollection autoCompleteStringCollection = new AutoCompleteStringCollection();
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = SQL;
			sqlConnection.Open();
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			if (sqlDataReader.HasRows)
			{
				while (sqlDataReader.Read())
				{
					autoCompleteStringCollection.Add(sqlDataReader[_ValueText].ToString());
				}
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			txt.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
			txt.AutoCompleteSource = AutoCompleteSource.CustomSource;
			txt.AutoCompleteCustomSource = autoCompleteStringCollection;
		}
		public void SelectValueCombobox(ComboBox objCbb, string objValue)
		{
			for (int i = 0; i < objCbb.Items.Count; i++)
			{
				ItemCombobox itemCombobox = (ItemCombobox)objCbb.Items[i];
				if (itemCombobox.Value == objValue)
				{
					objCbb.SelectedIndex = i;
					break;
				}
			}
		}
		public string VND(double NumCurrency)
		{
			string text = "";
			string text2 = "";
			string[] array = new string[10];
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			int num5 = 0;
			int num6 = 0;
			int num7 = 0;
			string text3 = "đồng";
			string text4 = "xu";
			if (NumCurrency != 0.0)
			{
				if (NumCurrency <= 922337203685477.0)
				{
					array[1] = "một";
					array[2] = "hai";
					array[3] = "ba";
					array[4] = "bốn";
					array[5] = "năm";
					array[6] = "sáu";
					array[7] = "bảy";
					array[8] = "tám";
					array[9] = "chín";
					num = (int)((NumCurrency - (double)((int)NumCurrency)) * 100.0);
					string text5 = NumCurrency.ToString().Trim();
					string str = new string(' ', 15 - text5.Length);
					text5 = str + text5;
					try
					{
						num3 = int.Parse(text5.Substring(0, 3));
					}
					catch
					{
						num3 = 0;
					}
					try
					{
						num4 = int.Parse(text5.Substring(3, 3));
					}
					catch
					{
						num4 = 0;
					}
					try
					{
						num5 = int.Parse(text5.Substring(6, 3));
					}
					catch
					{
						num5 = 0;
					}
					try
					{
						num6 = int.Parse(text5.Substring(9, 3));
					}
					catch
					{
						num6 = 0;
					}
					try
					{
						num7 = int.Parse(text5.Substring(12, 3));
					}
					catch
					{
						num7 = 0;
					}
					int i;
					if (num3 == 0 && num4 == 0 && num5 == 0 && num6 == 0 && num7 == 0)
					{
						text2 = "Không " + text3;
						i = 5;
					}
					else
					{
						text2 = "";
						i = 0;
					}
					while (i <= 5)
					{
						switch (i)
						{
						case 0:
							num2 = num3;
							text = "nghìn tỷ ";
							break;
						case 1:
							num2 = num4;
							text = "tỷ ";
							break;
						case 2:
							num2 = num5;
							text = "triệu ";
							break;
						case 3:
							num2 = num6;
							text = "nghìn";
							break;
						case 4:
							num2 = num7;
							text = text3;
							break;
						case 5:
							num2 = num;
							text = text4;
							break;
						}
						if (num2 != 0)
						{
							int num8 = num2 / 100;
							int num9 = (num2 - num8 * 100) / 10;
							int num10 = num2 - num8 * 100 - num9 * 10;
							text2 = text2.Trim() + ((text2.Length == 0) ? "" : " ") + ((num8 != 0) ? (array[num8].Trim() + " trăm ") : " không trăm ");
							if (num9 == 0 & num8 != 0 & num10 != 0)
							{
								text2 += "lẻ ";
							}
							else
							{
								if (num9 != 0)
								{
									text2 += ((num9 != 0 & num9 != 1) ? (array[num9].Trim() + " mười ") : "mười ");
								}
							}
							if (num9 != 0 & num10 == 5)
							{
								text2 = text2 + "lăm " + text + " ";
							}
							else
							{
								if (num9 > 1 & num10 == 1)
								{
									text2 = text2 + "mốt " + text + " ";
								}
								else
								{
									text2 += ((num10 != 0) ? (array[num10].Trim() + " " + text + " ") : (text + " "));
								}
							}
						}
						else
						{
							text2 += ((i == 4) ? (text3 + " ") : "");
						}
						i++;
					}
				}
			}
			return text2;
		}
		public double getPriceBaseInTabProducts(string productID)
		{
			string commandText = "SELECT P_PriceBase,GTGT_ID FROM [TabProducts] WHERE [TabProducts].[PID] =" + productID;
			double result = 0.0;
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = commandText;
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			if (sqlDataReader.HasRows)
			{
				while (sqlDataReader.Read())
				{
					double num = double.Parse(sqlDataReader["GTGT_ID"].ToString());
					double num2 = double.Parse(sqlDataReader["P_PriceBase"].ToString());
					result = num2 * (100.0 - num) / 100.0;
				}
			}
			else
			{
				result = 0.0;
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		public double getPriceBase1(string productID, DateTime tmpDateTime)
		{
			string commandText = "SELECT (SUM(TotalMoney)/SUM(Number)) AS PriceBase FROM [TabRepLink] WHERE [TabRepLink].[Pid] =" + productID + " AND [RepID] IN (SELECT RepID FROM TabRepList WHERE [RepDate]<=@DT ) ";
			double result = 0.0;
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = commandText;
			sqlCommand.Parameters.AddWithValue("@DT", tmpDateTime.ToShortDateString());
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			if (sqlDataReader.HasRows)
			{
				while (sqlDataReader.Read())
				{
					try
					{
						result = double.Parse(sqlDataReader["PriceBase"].ToString());
					}
					catch
					{
						result = this.getPriceBaseInTabProducts(productID);
					}
				}
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		public double TimGiaSanpham(string productID, int typeOfPrice)
		{
			double result = 0.0;
			string commandText;
			if (typeOfPrice == 0)
			{
				commandText = "SELECT [P_PriceBase] AS Price FROM [TabProducts] WHERE [PID]=" + productID;
			}
			else
			{
				if (typeOfPrice == 1)
				{
					commandText = "SELECT [P_PriceTrade] AS Price  FROM [TabProducts] WHERE [PID]=" + productID;
				}
				else
				{
					commandText = "SELECT [P_PriceRetail] AS Price  FROM [TabProducts] WHERE [PID]=" + productID;
				}
			}
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = commandText;
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			if (sqlDataReader.HasRows)
			{
				while (sqlDataReader.Read())
				{
					result = double.Parse(sqlDataReader["Price"].ToString());
				}
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		public string getSumOutput(string productID, string provideID, string month, string year)
		{
			string commandText = string.Concat(new string[]
			{
				"SELECT SUM(Number) AS SUMNUMBER FROM [TabReturnRepList],[TabReturnRepLink] WHERE [TabReturnRepList].[RepID] = [TabReturnRepLink].[RepID] AND datepart(m,RepDate) = ",
				month,
				" AND datepart(yyyy,RepDate) = ",
				year,
				" AND [RepProID] = '",
				provideID,
				"' AND [Pid] = ",
				productID
			});
			string text = "0";
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = commandText;
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			while (sqlDataReader.Read())
			{
				text = sqlDataReader["SUMNUMBER"].ToString();
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			if (text.Length == 0)
			{
				text = "0";
			}
			return text;
		}
		public string changeNumberToWord1(long NumberChange)
		{
			string text = "";
			int[] array = new int[4];
			this.numberArr[0] = "";
			this.numberArr[1] = "Một ";
			this.numberArr[2] = "Hai ";
			this.numberArr[3] = "Ba ";
			this.numberArr[4] = "Bốn ";
			this.numberArr[5] = "Năm ";
			this.numberArr[6] = "Sáu ";
			this.numberArr[7] = "Bảy ";
			this.numberArr[8] = "Tám ";
			this.numberArr[9] = "Chín ";
			this.moneyArr[0] = "Đồng ";
			this.moneyArr[1] = "Ngàn ";
			this.moneyArr[2] = "Triệu ";
			this.moneyArr[3] = "Tỷ ";
			if (NumberChange < 0L)
			{
				text = "Trừ ";
			}
			if (Math.Abs(NumberChange) > 999999999999L)
			{
				NumberChange = 0L;
			}
			long num = Math.Abs(NumberChange);
			array[3] = int.Parse((num / 1000000000L).ToString());
			num -= long.Parse(array[3].ToString() + "000000000");
			array[2] = int.Parse((num / 1000000L).ToString());
			array[1] = int.Parse((num % 1000000L / 1000L).ToString());
			array[0] = int.Parse((num % 1000L).ToString());
			int num2;
			if (array[3] > 0)
			{
				num2 = 3;
			}
			else
			{
				if (array[2] > 0)
				{
					num2 = 2;
				}
				else
				{
					if (array[1] > 0)
					{
						num2 = 1;
					}
					else
					{
						num2 = 0;
					}
				}
			}
			for (int i = num2; i >= 0; i--)
			{
				try
				{
					text += this.ChangeNumToWord(array[i]);
				}
				catch
				{
				}
				text = text + this.moneyArr[i].ToString() + " ";
			}
			text = text.ToLower().Trim();
			text = text.Substring(0, 1).ToUpper() + text.Remove(0, 1);
			return text.Trim().Replace("  ", " ").Replace("triệu ngàn đồng", "triệu đồng").Replace("tỷ triệu ngàn đồng", "tỷ đồng");
		}
		private string ChangeNumToWord(int NumVar)
		{
			string text = "";
			int num = int.Parse((NumVar / 100).ToString());
			int num2 = int.Parse((NumVar % 100 / 10).ToString());
			int num3 = NumVar % 10;
			if (num == 0 && num2 == 0 && num3 == 0)
			{
				text = "";
			}
			if (num != 0)
			{
				text = text + this.numberArr[num].ToString() + " Trăm ";
				if (num2 == 0 && num3 != 0)
				{
					text += "Lẻ ";
				}
			}
			if (num2 != 0 && num2 != 1)
			{
				text = text + this.numberArr[num2].ToString() + " Mươi ";
				if (num2 == 0 && num3 != 0)
				{
					text += " Lẻ ";
				}
			}
			if (num2 == 1)
			{
				text += " Mười ";
			}
			int num4 = num3;
			if (num4 != 1)
			{
				if (num4 != 5)
				{
					text += this.numberArr[num3].ToString();
				}
				else
				{
					if (num2 == 0)
					{
						text += this.numberArr[num3].ToString();
					}
					else
					{
						text += " Lăm ";
					}
				}
			}
			else
			{
				if (num2 != 0 && num2 != 1)
				{
					text += " Mốt ";
				}
				else
				{
					text += this.numberArr[num3].ToString();
				}
			}
			return text;
		}
		public string getCompanyInfor(string Field)
		{
			string commandText = "SELECT " + Field + " FROM [TabCompany] WHERE [ComID] = 'COM01'";
			string result = "";
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = commandText;
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			while (sqlDataReader.Read())
			{
				result = sqlDataReader[Field].ToString();
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		public int updateConfig(int TypeDate)
		{
			int result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("ActionOnTabConfigDate", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("TypeDate", SqlDbType.SmallInt);
				sqlCommand.Parameters["TypeDate"].Value = TypeDate;
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = 0;
			}
			catch
			{
				result = 1;
			}
			return result;
		}
		public int updateConfigPrint(int TypeDate, string billFooter)
		{
			int result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("ActionOnTabConfigPrint", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("@TypePrint", SqlDbType.SmallInt);
				sqlCommand.Parameters.Add("@billFooter", SqlDbType.NVarChar, 2000);
				sqlCommand.Parameters["@TypePrint"].Value = TypeDate;
				sqlCommand.Parameters["@billFooter"].Value = billFooter;
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = 0;
			}
			catch
			{
				result = 1;
			}
			return result;
		}
		public string getBillFooter()
		{
			string text = "0";
			string result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [billFooter] FROM [TabConfigDate]";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					text = sqlDataReader["billFooter"].ToString();
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = text;
			}
			catch
			{
				result = "";
			}
			return result;
		}
		public string getTypeDate()
		{
			string text = "0";
			string result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [TypeDate] FROM [TabConfigDate]";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					text = sqlDataReader["TypeDate"].ToString();
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = text;
			}
			catch
			{
				result = "0";
			}
			return result;
		}
		public string getTypePrint()
		{
			string text = "0";
			string result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [TypePrint] FROM [TabConfigDate]";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					text = sqlDataReader["TypePrint"].ToString();
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = text;
			}
			catch
			{
				result = "0";
			}
			return result;
		}
		public string GetNextBarcode()
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "SELECT [BarcodeMax] FROM [TabConfig]";
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			string text = "";
			try
			{
				sqlDataReader.Read();
				text = (int.Parse(sqlDataReader["BarcodeMax"].ToString()) + 1).ToString();
				while (12 - text.Length > 0)
				{
					text = "0" + text;
				}
				text += this.CreateChecksum(text);
			}
			catch
			{
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			return text;
		}
		private string CreateChecksum(string EAN)
		{
			int num = 0;
			for (int i = EAN.Length - 1; i >= 0; i--)
			{
				if (i % 2 == 0)
				{
					num += int.Parse(EAN.Substring(i, 1));
				}
				else
				{
					num += 3 * int.Parse(EAN.Substring(i, 1));
				}
			}
			int num2 = 10 - num % 10;
			return (num2 % 10).ToString();
		}
		public void SetBarcode(string _Barcode)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			string text = "";
			try
			{
				text = int.Parse(_Barcode.Substring(0, 12)).ToString();
				while (12 - text.Length > 0)
				{
					text = "0" + text;
				}
			}
			catch
			{
			}
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [BarcodeMax] = '" + text + "'";
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public double GetPromoteMoney()
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "SELECT [PromoteMoney]FROM [TabConfig]";
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			double result = 0.0;
			try
			{
				sqlDataReader.Read();
				result = double.Parse(sqlDataReader["PromoteMoney"].ToString());
			}
			catch
			{
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		public int GetPromote()
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "SELECT [Promote] FROM [TabConfig]";
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			int result = 0;
			try
			{
				sqlDataReader.Read();
				result = int.Parse(sqlDataReader["Promote"].ToString());
			}
			catch
			{
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		public int GetUseChangeProduct()
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "SELECT [UseChangeProduct] FROM [TabConfig]";
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			int result = 1;
			try
			{
				sqlDataReader.Read();
				result = int.Parse(sqlDataReader["UseChangeProduct"].ToString());
			}
			catch
			{
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		public void SetPromoteMoney(double _Promote)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [PromoteMoney] = " + _Promote;
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public void SetPromote(int _Promote)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [Promote] = " + _Promote;
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public void SetUseChangeProduct(int UseChangeProduct)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [UseChangeProduct] = " + UseChangeProduct;
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public bool checkWarningNumber()
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [usingWarningNumber] FROM [TabConfig] WHERE [usingWarningNumber] = 1";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				if (sqlDataReader.HasRows)
				{
					result = true;
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public bool checkWarningDate()
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [WarningEnable] FROM [TabConfig] WHERE [WarningEnable] = 1";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				if (sqlDataReader.HasRows)
				{
					result = true;
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public void setWarningDayStatus(int status)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [usingWarningNumber] = " + status.ToString();
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public void setWarningDateStatus(int status)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [WarningEnable] = " + status.ToString();
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public int getWarningDay()
		{
			int result = 0;
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "SELECT [WarningDay] FROM [TabConfig]";
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			while (sqlDataReader.Read())
			{
				result = int.Parse(sqlDataReader["WarningDay"].ToString());
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		public void setWarningDay(int warningDay)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [WarningDay] = " + warningDay.ToString();
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public int getWarningNumberProduct()
		{
			int result = 0;
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "SELECT [WarningNumber] FROM [TabConfig]";
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			while (sqlDataReader.Read())
			{
				result = int.Parse(sqlDataReader["WarningNumber"].ToString());
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		public void setWarningNumber(int Number)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [WarningNumber] = " + Number.ToString();
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public bool getNoAllowOtherEditBill()
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [Active] FROM [TabSysParamater] WHERE [ID] = 'NoAllowOtherEditBill'", sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = (sqlDataReader["Active"].ToString() == "True");
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public bool getAllowSellSuppen()
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [Active] FROM [TabSysParamater] WHERE [ID] = 'AllowSellSuppen'", sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = (sqlDataReader["Active"].ToString() == "True");
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public bool getAllowEditPrice()
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [Active] FROM [TabSysParamater] WHERE [ID] = 'AllowEditPrice'", sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = (sqlDataReader["Active"].ToString() == "True");
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public bool getAllowSellExpired()
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [Active] FROM [TabSysParamater] WHERE [ID] = 'AllowSellExpired'", sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = (sqlDataReader["Active"].ToString() == "True");
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public bool getAllowDouble()
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [Active] FROM [TabSysParamater] WHERE [ID] = 'AllowDouble'", sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = (sqlDataReader["Active"].ToString() == "True");
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public bool getNoEditAffterPrint()
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [Active] FROM [TabSysParamater] WHERE [ID] = 'NoEditAffterPrint'", sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = (sqlDataReader["Active"].ToString() == "True");
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public bool getSellOnPublicPrice()
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [Active] FROM [TabSysParamater] WHERE [ID] = 'SellOnPublicPrice'", sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = (sqlDataReader["Active"].ToString() == "True");
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public bool getAllowExportWhenOuput()
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [Active] FROM [TabSysParamater] WHERE [ID] = 'AllowExportWhenOuput'", sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = (sqlDataReader["Active"].ToString() == "True");
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public bool getRetailByBarcode()
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [Active] FROM [TabSysParamater] WHERE [ID] = 'RetailByBarcode'", sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = (sqlDataReader["Active"].ToString() == "True");
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public bool getBasePrice()
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [Active] FROM [TabSysParamater] WHERE [ID] = 'BasePrice'", sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = (sqlDataReader["Active"].ToString() == "True");
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public double getWarningDebt()
		{
			double result = 0.0;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [Value] FROM [TabSysParamater] WHERE [ID] = 'WarningDebt'", sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = double.Parse(sqlDataReader["Value"].ToString());
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public int getTypeBarcodePrint()
		{
			int result = 0;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [TypeBarcodePrint] FROM [TabConfig]", sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = int.Parse(sqlDataReader["TypeBarcodePrint"].ToString());
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public void SetTypeBarcodePrint(int TypeBarcodePrint)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [TypeBarcodePrint] =" + TypeBarcodePrint;
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public void SetUpdatePriceOrNot(int updateOrNot)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [UpdatePrice] =" + updateOrNot;
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public int GetUpdatePriceOrNot()
		{
			int result = 0;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [UpdatePrice] FROM [TabConfig]";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = int.Parse(sqlDataReader["UpdatePrice"].ToString());
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public int GetBarcodePosition()
		{
			int result = 0;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [BarcodePosition] FROM [TabConfig]";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = int.Parse(sqlDataReader["BarcodePosition"].ToString());
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public int GetPrintBarcodeType()
		{
			int result = 1;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [PrintBarcodeType] FROM [TabConfig]";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = int.Parse(sqlDataReader["PrintBarcodeType"].ToString());
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public void SetPrintBarcodeType(int _PrintBarcodeType)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [PrintBarcodeType] = " + _PrintBarcodeType;
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public void SetPerfixIn(string _PerfixIn)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [PerfixIn] = '" + _PerfixIn + "'";
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public void SetPerfixOut(string _PerfixOut)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [PerfixOut] = '" + _PerfixOut + "'";
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public void SetPerfixOutRetail(string _PerfixOutRetail)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [PerfixOutRetail] = '" + _PerfixOutRetail + "'";
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public string GetPerfixIn()
		{
			string result = "";
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [PerfixIn] FROM [TabConfig]";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = sqlDataReader["PerfixIn"].ToString();
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public string GetPerfixOut()
		{
			string result = "";
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [PerfixOut] FROM [TabConfig]";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = sqlDataReader["PerfixOut"].ToString();
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public string GetPerfixOutRetail()
		{
			string result = "";
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [PerfixOutRetail] FROM [TabConfig]";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = sqlDataReader["PerfixOutRetail"].ToString();
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public bool GetFixedStockRetail()
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [Active] FROM [TabSysParamater] WHERE [ID] = 'FixedStockRetail'", sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = (sqlDataReader["Active"].ToString() == "True");
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public void SetBarcodePosition(int _BarcodePosition)
		{
			SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "UPDATE [TabConfig] SET [BarcodePosition] = " + _BarcodePosition;
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public void txtObject_Leave(object sender)
		{
			TextBox textBox = (TextBox)sender;
			try
			{
				if (textBox.Text != "" && textBox.Text != "0")
				{
					textBox.Text = string.Format(Program.lenAffterDecimal, double.Parse(textBox.Text));
				}
				else
				{
					textBox.Text = "0";
				}
			}
			catch
			{
				textBox.Text = "0";
			}
		}
		public void txtObject_Number_Leave(object sender)
		{
			TextBox textBox = (TextBox)sender;
			try
			{
				if (textBox.Text != "" && textBox.Text != "0")
				{
					textBox.Text = string.Format("{0:0,0}", double.Parse(textBox.Text));
				}
				else
				{
					textBox.Text = "0";
				}
			}
			catch
			{
				textBox.Text = "0";
			}
		}
		public string getWarehouse(string UserName)
		{
			string result = "";
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [WareHouseID] FROM [TabUser] WHERE [UserName] = '" + UserName + "'";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = sqlDataReader["WareHouseID"].ToString();
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
	}
}
